package com.andyage.admin.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.andyage.admin.bean.AdfeedbackBean;
import com.andyage.admin.dao.AdfeedbackMapper;
import com.andyage.admin.service.IAdfeedbackService;
import com.andyage.util.JsonContent;

import net.sf.json.JSONObject;

@Service
public class AdfeedbackServiceImpl implements IAdfeedbackService {
	@Resource
	private AdfeedbackMapper feedbackMapper;

	@Override
	public String updateFeedBackInfo(AdfeedbackBean feedback) throws Exception {
		int result = feedbackMapper.updateFeedBackInfo(feedback);
		JSONObject json = new JSONObject();
		if (result > 0) {
			json.accumulate("result", 1);
			json.accumulate("tips", "成功修改" + result + "条");
		} else {
			json.accumulate("result", 0);
			json.accumulate("tips", "修改失败");
		}
		return json.toString();
	}

	@Override
	public String queryFeedBackInfo(AdfeedbackBean feedback) throws Exception {
		List<AdfeedbackBean> list = feedbackMapper.queryFeedBackInfo(feedback);
		int total = feedbackMapper.queryFeedBackInfoCount(feedback);
		String json = JsonContent.getJsonArray(list, total);
		return json;
	}

	@Override
	public String deleteFeedBackInfo(String feedBackId) throws Exception {
		int result = feedbackMapper.deleteFeedBackInfo(feedBackId);
		JSONObject json = new JSONObject();
		if (result > 0) {
			json.accumulate("result", 1);
			json.accumulate("tips", "成功删除" + result + "条");
		} else {
			json.accumulate("result", 0);
			json.accumulate("tips", "删除失败");
		}
		return json.toString();
	}

}
